package com.gzx.plugin.tjzy.modular.repair.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.Random;

/**
 * 随机字符串工具
 */
@Slf4j
public class RandomStringUtil {
    private RandomStringUtil() {
    }

    // 定义可选字符集：大写字母 A-Z 和数字 0-9
    private static final String CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    private static final Random random = new Random();

    /**
     * 生成指定长度的随机字符串
     *
     * @param length 字符串长度
     * @return 随机字符串
     */
    public static String generateRandomString(int length) {
        StringBuilder sb = new StringBuilder(length);
        for (int i = 0; i < length; i++) {
            int index = random.nextInt(CHARACTERS.length());
            sb.append(CHARACTERS.charAt(index));
        }
        return sb.toString();
    }

    //从号码池中随机获取一个号码
    public static String getRandomPhone(String linePool) {
        // 按逗号分割字符串成数组
        String[] values = linePool.split(",");

        int randomIndex = random.nextInt(values.length);

        // 根据随机索引获取值
        return values[randomIndex];
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++) {
            String randomString = generateRandomString(20);
            log.info("生成的随机字符串: {}", randomString);
        }
    }
}
